using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarNCDDiscountDB
    {
        public CarNCDDiscountDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarNCDDiscount carncddiscount)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarNCDDiscountInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCarNCDDiscountId", carncddiscount.ProviderCarNCDDiscountId);
            _sPara.Add("@ProviderCompanyId", carncddiscount.ProviderCompanyId);
            _sPara.Add("@NCDPercent", carncddiscount.NCDPercent);
            _sPara.Add("@DiscountPercent", carncddiscount.DiscountPercent);
            _sPara.Add("@RefCEUserId", carncddiscount.RefCEUserId);
            _sPara.Add("@Status", carncddiscount.Status);
            _sPara.Add("@FInfo1", carncddiscount.FInfo1);
            _sPara.Add("@DInfo1", carncddiscount.DInfo1);
            //_sPara.Add("@Info1", template.Info1);
            //_sPara.Add("@Info2", template.Info2);
            //_sPara.Add("@Info3", template.Info3);
            //_sPara.Add("@Info4", template.Info4);
            //_sPara.Add("@Info5", template.Info5);
            //_sPara.Add("@NInfo1", template.NInfo1);
            //_sPara.Add("@NInfo2", template.NInfo2);            
            //_sPara.Add("@FInfo2", template.FInfo2);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public CarNCDDiscount GetProviderCarNCDDiscount(Int64 ProviderCompanyId, Int32 NCDPercent)
        {
            CarNCDDiscount _ncddiscount = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarNCDDiscountSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@NCDPercent", NCDPercent);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _ncddiscount = new CarNCDDiscount();
                    _ncddiscount = FillDataRecord(_dt, 0);
                }
            }
            return _ncddiscount;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        private CarNCDDiscount FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarNCDDiscount myCarNCDDiscount = new CarNCDDiscount();
            myCarNCDDiscount.ProviderCarNCDDiscountId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarNCDDiscountId"].ToString());
            myCarNCDDiscount.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarNCDDiscount.NCDPercent = Convert.ToInt32(myDataTable.Rows[RowId]["NCDPercent"].ToString());
            myCarNCDDiscount.DiscountPercent = Convert.ToInt32(myDataTable.Rows[RowId]["DiscountPercent"].ToString());
            myCarNCDDiscount.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarNCDDiscount.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            myCarNCDDiscount.CreatedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["CreatedDate"].ToString());
            myCarNCDDiscount.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            if (myDataTable.Rows[RowId]["FInfo1"].ToString() != "")
                myCarNCDDiscount.FInfo1 = Convert.ToSingle(myDataTable.Rows[RowId]["FInfo1"].ToString());

            if (myDataTable.Rows[RowId]["DInfo1"].ToString() != "")
                myCarNCDDiscount.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["DInfo1"].ToString());
            else
                myCarNCDDiscount.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            return myCarNCDDiscount;
        }

    }
}